package org.lex.net.proxy.ui;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.LayoutStyle;
import javax.swing.SwingConstants;

import org.lex.net.proxy.ProxyManager;
import org.lex.swing.Swings;


public class ProxyManagerPane extends javax.swing.JPanel {
	private JButton removeButton;
	private JButton addButton;
	private JButton makeDefaultButton;
	private JTable table;
	private JScrollPane scrollPane;
	private JButton editButton;
	private ProxyManager tableModel;

	/**
	 * Auto-generated main method to display this JPanel inside a new JFrame.
	 */
	public static void main(String[] args) {
		Swings.show(new ProxyManagerPane(), false);
	}

	public ProxyManagerPane() {
		super();
		this.tableModel = new ProxyManager();
		initialize();
	}

	private void initialize() {
		GroupLayout thisLayout = new GroupLayout((JComponent) this);
		this.setLayout(thisLayout);
		thisLayout.setHorizontalGroup(thisLayout
				.createSequentialGroup()
				.addContainerGap()
				.addGroup(
						thisLayout
								.createParallelGroup()
								.addGroup(
										GroupLayout.Alignment.LEADING,
										thisLayout
												.createSequentialGroup()
												.addComponent(getMakeDefaultButton(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
														GroupLayout.PREFERRED_SIZE)
												.addGap(0, 120, Short.MAX_VALUE)
												.addComponent(getAddButton(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
														GroupLayout.PREFERRED_SIZE)
												.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 1, GroupLayout.PREFERRED_SIZE)
												.addComponent(getEditButton(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
														GroupLayout.PREFERRED_SIZE)
												.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 1, GroupLayout.PREFERRED_SIZE)
												.addComponent(getRemoveButton(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
														GroupLayout.PREFERRED_SIZE))
								.addComponent(getScrollPane(), GroupLayout.Alignment.LEADING, 0, 376, Short.MAX_VALUE)).addContainerGap());
		thisLayout.setVerticalGroup(thisLayout
				.createSequentialGroup()
				.addContainerGap()
				.addComponent(getScrollPane(), 0, 244, Short.MAX_VALUE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addGroup(
						thisLayout
								.createParallelGroup(GroupLayout.Alignment.BASELINE)
								.addComponent(getRemoveButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
										GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(getEditButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addComponent(getAddButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addComponent(getMakeDefaultButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
										GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)).addContainerGap());
		thisLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] { getRemoveButton(), getEditButton(), getAddButton() });
		setPreferredSize(new Dimension(400, 300));
	}

	private JButton getRemoveButton() {
		if (removeButton == null) {
			removeButton = new JButton();
			removeButton.setText("Remove");
		}
		return removeButton;
	}

	private JButton getEditButton() {
		if (editButton == null) {
			editButton = new JButton();
			editButton.setText("Edit");
		}
		return editButton;
	}

	private JButton getAddButton() {
		if (addButton == null) {
			addButton = new JButton();
			addButton.setText("Add");
		}
		return addButton;
	}

	private JButton getMakeDefaultButton() {
		if (makeDefaultButton == null) {
			makeDefaultButton = new JButton();
			makeDefaultButton.setText("Make Default");
		}
		return makeDefaultButton;
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}

	private JTable getTable() {
		if (table == null) {
			table = new JTable(tableModel);
		}
		return table;
	}
}
